package org.zxp.javacheck.iterator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @program: effectiveJava
 * @description:
 * @author: X-Pacific zhang
 * @create: 2019-06-09 17:40
 **/
public class IteratorTest {
    public static void main(String[] args){
        //这样写不行
//        List arr = Arrays.asList("1","2","3","4","5");
        List arr = new ArrayList();
        arr.add("1");
        arr.add("2");
        arr.add("3");
        arr.add("4");
        arr.add("5");
        Iterator iterator = arr.iterator();
        while (iterator.hasNext()){
            String str = (String) iterator.next();
            System.out.println(arr.size());
            if("3".equals(str)){
                iterator.remove();
                System.out.println(arr.size());
            }
        }
        arr.forEach(o -> System.out.println(o));

    }
}
